package controller.action;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class PMAction extends Action {

	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		int ergebnis;
		RequestDispatcher rd;
		HttpSession s;
		
		s  = request.getSession(true);
		rd = request.getRequestDispatcher("/frontcontroller/resultat.jsp");
        
		if (request.getParameter("submit").equals("+")){
			ergebnis = Integer.valueOf(request.getParameter("zahl1")) + Integer.valueOf(request.getParameter("zahl2"));
				
		}
		else{
			ergebnis = Integer.valueOf(request.getParameter("zahl1")) - Integer.valueOf(request.getParameter("zahl2"));
		}
		
		s.putValue("ergebnis", ergebnis);
		rd.forward(request, response);
	}

}
